/*
 * @描述: 
 * @创建者: kilomChou
 * @Date: 2021-04-11 17:21:46
 * @最后编辑: kilomChou
 * @LastEditTime: 2021-05-10 22:26:32
 */
import { RandUtil } from "../../util/RandUtil";
import BaseAI, { IBaseAI } from "./BaseAI";

export interface IAITurn extends IBaseAI {
    turnSpeed: number | [number, number]
}

/** 智能随机转弯 */
export default class AITurn extends BaseAI {

    constructor(obj: IAITurn) {
        super(obj)
        this._turnSpeed = this.toMinMax(obj.turnSpeed)
    }

    private _turnSpeed: number[]
    private _turnSpd!: number

    getKey(): string { return "ai_turn" + this.snake.id }

    aiStart() {
        let turn = RandUtil.chance(0.5) ? -1 : 1
        this._turnSpd = turn * RandUtil.rand2(this._turnSpeed)
    }

    ai(dt: number): void {
        let head = this.head
        let turnAng = this.snake.getTurnSpd() * this._turnSpd * dt
        this.snake.toAng = head.ang + turnAng;
    }

    aiStop() {

    }

}